<!DOCTYPE html>
<html lang="cn" xmlns="">
<head>
    <meta charset="UTF-8">
    <title>金额转换</title>
    <script type="text/javascript">
        var caps = "零壹贰叁肆伍陆柒捌玖".split("");
        var units = "仟佰拾萬仟佰拾億仟佰拾萬仟佰拾元角分".split("");

        function fun() {
            var number = document.getElementById("number").value;
            var reg = /^(([1-9]\d{0,14})|0)(\.\d{1,2})?$/;
            if (!reg.test(number)) {
                alert("数字格式不正确！");
            }
            var index = number.indexOf(".");
            if (index === -1) {
                number = number + '.00';
            } else {
                number = number + '0';
            }
            index = number.indexOf("."); // 拼接字符重置.定位，重新定义index
            var part1 = number.substring(0, index);
            var part2 = number.substring(index + 1, index + 3)
            var money = (part1 + part2).split("");
            var res = "";
            var i = money.length - 1;
            var j = units.length - 1;
            for (; i >= 0; i--, j--) {
                res = caps[money[i]] + units[j] + res;
            }
            document.getElementById("res").innerHTML = res;
        }
    </script>
</head>
<body>
<div>
    <label>
        输入数字：
        <input type="text" id="number">
        <button type="button" onclick="fun()">转换</button>
        <br>
    </label>
    大写金额：
    <div id="res"></div>
</div>
</body>
</html>